<?php

namespace App\Admin\Controllers;
use App\Admin\Controllers\PreviewCode;
use App\Admin\Components\SettingForm;
use App\Http\Controllers\Controller;
use App\Models\Setting;
use App\Models\Transaction;
use App\Models\UserWallet;
use Dcat\Admin\Layout\Content;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use App\Models\User;
use App\Models\UserWithdraw;
use App\Models\Adreward;
use App\Models\Commission;
use App\Admin\Metrics\Examples\TotalUsers;
use App\Admin\Metrics\Examples\NewUsers;
use App\Admin\Metrics\Examples\NewDevices;
use App\Admin\Metrics\Examples\SevenAddUser;
use App\Admin\Metrics\Examples\SevenPlatformRevenue;
use App\Admin\Metrics\Examples\SevenPersonalGain;
use App\Admin\Metrics\Examples\SevenTeamRevenue;
use App\Admin\Metrics\Examples\SevenPromotionRevenue;

use Dcat\Admin\Layout\Row;
class BigScreenController extends Controller{
    use PreviewCode;
    public function index(Content $content)
    {

//        $todayIncUserNum = User::where('created_at','gt',Carbon::today())->count();
//        $todayOnlineUserNum = User::where('last_login_at','gt',Carbon::today())->count();
//        $yesterdayIncUserNum = User::whereBetween('created_at',[Carbon::yesterday(),Carbon::today()])->count();
//        $totalUserNum = User::count();
//        $totalWithdrawAmount = UserWithdraw::where('status','approved')->sum('money');
//        $todayIncomeAmount = Adreward::where('created_at','gt',Carbon::today())->sum('user_money');
//        $yesterdayIncomeAmount = Adreward::whereBetween('created_at',[Carbon::yesterday(),Carbon::today()])->sum('user_money');
        $exchangeRate = Setting::get('exchange_rate');
        $totalUserNum = User::count();
        $Adreward= Adreward::sum('user_money');//累计个人红包收益人民币
        $Commission= Commission::whereIn('source',['group_invite','group_cash'])->sum('user_money');//累计团队红包收益人民币
        $direct_invite= Commission::whereIn('source',['direct_invite'])->sum('user_money');//累计推广奖励人民币
        $reward_coins=round(UserWallet::sum('reward_coins')/$exchangeRate,4) ;//累计未提现金额
        $locked_coins= Transaction::where('status','approved')->sum('trans_amount');//累计已提现金额

        $screenData = [
            "totalUserNum"=>$totalUserNum,
            "Adreward"=>$Adreward,
            "Commission"=>$Commission,
            "direct_invite"=>$direct_invite,
            "reward_coins"=>$reward_coins,
            "locked_coins"=>$locked_coins,



        ];






        return $content
            ->title('数据展示')
            ->description('数据展示')
            ->body(view('screen', compact('screenData')))
            ->body(function (Row $row) {
                $row->column(4, new SevenAddUser());//七天每天新增用户
                $row->column(4, new SevenPlatformRevenue());//七天每天平台收益
                $row->column(4, new SevenPersonalGain());//七天每天个人红包收益
            })->body(function (Row $row) {
                $row->column(4, new SevenTeamRevenue());//七天每天团队红包收益
                $row->column(4, new SevenPromotionRevenue());//七天每天推广奖励收益
             //   $row->column(4, new SevenPersonalGain());//七天每天推广奖励收益
            });
    }
}
